package com.huan.iteye.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 普通的定时任务，继承此类的定时任务，到了执行时间自动执行
 *
 * @author huan.fu
 * @date 2018/9/10 - 17:23
 */
@Slf4j
public abstract class AbstractCustomJob implements Job {

	@Override
	public void execute(JobExecutionContext jobExecutionContext) {
		String jobName = (String) jobExecutionContext.getJobDetail().getJobDataMap().get("jobName");
		try {
			log.info("开始(start)执行:[{}]", jobName);
			String workDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
			doExecute(workDate);
			log.info("完成(end)执行:[{}]", jobName);
		} catch (Exception e) {
			log.error(String.format("执行任务:[%s]失败", jobName), e);
		}
	}

	/**
	 * 执行业务逻辑
	 *
	 * @param workDate 执行日期
	 */
	public abstract void doExecute(String workDate);
}
